package sliceops

import "fmt"

func printSlice(s []int)  {
	fmt.Println(s, len(s), cap(s))
}

func main() {
	var s []int //Zero value for slice is nil

	for i := 0; i<100; i++ {
		printSlice(s)
		s = append(s, 2*i + 1)
	}
	fmt.Println(s)


	s1 := []int{2,4,6,8,10,12,14,16}
	printSlice(s1)

	s2 := make([]int, 16)  //(类型， 长度)
	s3 := make([]int, 10, 32) //(类型， 长度，cap 容量)

	printSlice(s2)
	printSlice(s3)

	fmt.Println("Copying slice")
	copy(s2, s1)
	printSlice(s2)
	fmt.Println("Deleting elements from slice")
	//s2 = append(s2[:3], s2[4:]...)  删除中间的元素

	//删除头尾
	fmt.Println("Popping from front")
	front := s2[0]
	s2 = s2[1:]

	fmt.Println("Popping from back")
	back := s2[len(s2)-1]
	s2 = s2[:len(s2)-1]

	fmt.Println(front, back, s2)

}